#define ASPECT_FILL(_ASPECT) \
   aspect: _ASPECT _ASPECT; aspect_preference: NONE;
#define TILED_PATTERN(_WIDTH, _HEIGHT) \
   fill { size { relative: 0.0 0.0; offset: _WIDTH _HEIGHT; } }
#define TILED_HORIZ(_WIDTH) \
   fill { size { relative: 0.0 1.0; offset: _WIDTH 0; } }
#define FIXED_SIZE(_WIDTH, _HEIGHT) \
   min: _WIDTH _HEIGHT; max: _WIDTH _HEIGHT; fixed: 1 1;

#define SHELFPAD 3
#define ICMIN 15
#define RSZCOL  0 0 0 0
#define RSZCOL2 0 0 0 0
#define RSZMINW 44
#define RSZMINH 10

#define SPACER_TEXT "NN";

#define BACKGROUND_COMP LOSSY 91
//#define BACKGROUND_COMP LOSSY_ETC1
//#define BACKGROUND_COMP LOSSY_ETC2
#define BACKGROUND_IMG \
   set { name: "background"; \
     image { image: "p-5120.png" BACKGROUND_COMP; size: 3841 2161 51200 28800; } \
     image { image: "p-3840.png" BACKGROUND_COMP; size: 3201 1801  3840  2160; } \
     image { image: "p-3200.png" BACKGROUND_COMP; size: 2561 1441  3200  1800; } \
     image { image: "p-2560.png" BACKGROUND_COMP; size: 1921 1081  2560  1440; } \
     image { image: "p-1920.png" BACKGROUND_COMP; size: 1601  900  1920  1080; } \
     image { image: "p-1600.png" BACKGROUND_COMP; size: 1281  721  1600   900; } \
     image { image: "p-1280.png" BACKGROUND_COMP; size:    0    0  1280   720; } \
   }

#define PAT_FILL_SCALE(_w, _h) \
   part { name: "_pat_sizer"; type: SPACER; \
      scale: 1; \
      description { state: "default" 0.0; \
         rel2.relative: 0.0 0.0; \
         fixed: 1 1; \
         min: 100 100; max: 100 100; \
      } \
   } \
   program { signal: "resize"; source: ""; \
      script { \
         new x, y, w, h; \
         get_geometry(PART:"_pat_sizer", x, y, w, h); \
         custom_state(PART:"pat", "default", 0.0); \
         set_state_val(PART:"pat", STATE_FILL_SIZE, 0, 0, (w*_w)/100, (h*_h)/100); \
         set_state(PART:"pat", "custom", 0.0); \
      } \
   }

#define DARK_GREY_BG_COLOR 48 48 48 255
#define DARK_GREY_BG_DISABLED_COLOR 64 64 64 255

#define SHAD(_to, _clip, _img, _l, _r, _t, _b, _scale) \
      scale: 1; clip_to: _clip; \
      description { state: "default" 0.0; \
         rel.to: _to; \
         image.normal: _img; \
         image.border: 75 75 75 75; \
         image.border_scale: 1; \
         image.border_scale_by: _scale; \
         rel1.offset: (-_l) (-_t); \
         rel2.offset: (_r-1) (_b-1); \
         fill.smooth: 1; \
         offscale; \
      }
#define SHAD_CLIP(_to, _clip, _l, _r, _t, _b, _scale) \
   part { type: RECT; name: "_shcl1"; \
      scale: 1; clip_to: _clip; \
      description { state: "default" 0.0; \
         rel.to: _to; \
         rel1.offset: (-_l) (-_t); \
         rel2.offset: (_r-1) -1; \
         rel2.relative: 1.0 0.0; \
         offscale; \
      } \
   } \
   part { type: RECT; name: "_shcl2"; \
      scale: 1; clip_to: _clip; \
      description { state: "default" 0.0; \
         rel.to: _to; \
         rel1.offset: (-_l) 0; \
         rel1.relative: 0.0 1.0; \
         rel2.offset: (_r-1) (_b-1); \
         offscale; \
      } \
   } \
   part { type: RECT; name: "_shcl3"; \
      scale: 1; clip_to: _clip; \
      description { state: "default" 0.0; \
         rel.to: _to; \
         rel1.offset: (-_l) 0; \
         rel2.offset: -1 -1; \
         rel2.relative: 0.0 1.0; \
         offscale; \
      } \
   } \
   part { type: RECT; name: "_shcl4"; \
      scale: 1; clip_to: _clip; \
      description { state: "default" 0.0; \
         rel.to: _to; \
         rel1.offset: 0 0; \
         rel1.relative: 1.0 0.0; \
         rel2.offset: (_r-1) -1; \
         offscale; \
      } \
   }

#define WIN_SHAD(_to, _clip, _img, _l, _r, _t, _b, _scale) \
   SHAD_CLIP(_to, _clip, _l, _r, _t, _b, _scale) \
   part { name: "_sh1"; mouse_events: 0; \
      SHAD(_to, "_shcl1", _img, _l, _r, _t, _b, _scale) \
   } \
   part { name: "_sh2"; mouse_events: 0; \
      SHAD(_to, "_shcl2", _img, _l, _r, _t, _b, _scale) \
   } \
   part { name: "_sh3"; mouse_events: 0; \
      SHAD(_to, "_shcl3", _img, _l, _r, _t, _b, _scale) \
   } \
   part { name: "_sh4"; mouse_events: 0; \
      SHAD(_to, "_shcl4", _img, _l, _r, _t, _b, _scale) \
   }

#define WIN_SHADOW \
   image.normal: "win_shadow.png"; \
   image.border: 32 32 32 32; \
   image.border_scale: 1; \
   image.border_scale_by: 1.0; \
   image.middle: 0; \
   rel1.offset: -21 -14; \
   rel2.offset: 20 27; \
   fill.smooth: 0; \
   offscale
#define WIN_SHADOW_SMALL \
   image.normal: "win_shadow.png"; \
   image.border: 32 32 32 32; \
   image.border_scale: 1; \
   image.border_scale_by: 0.5; \
   image.middle: 0; \
   rel1.offset: -10 -7; \
   rel2.offset: 9 10; \
   fill.smooth: 0; \
   offscale
#define WIN_SHADOW_SPACER \
   rel1.offset: 21 14; \
   rel2.offset: -22 -29; \
   offscale
#define WIN_MENU_SHADOW \
   image.normal: "win_menu_shadow.png"; \
   image.border: 32 32 32 32; \
   image.border_scale: 1; \
   image.border_scale_by: 1.0; \
   image.middle: 0; \
   rel1.offset: -21 -14; \
   rel2.offset: 20 27; \
   fill.smooth: 0; \
   offscale
#define WIN_SHADOW_ANGLE_SMALL(_img) \
   image.normal: _img; \
   image.border: 32 32 32 32; \
   image.border_scale: 1; \
   image.border_scale_by: 0.5; \
   image.middle: 0; \
   rel1.offset: -10 -7; \
   rel2.offset: 9 13; \
   fill.smooth: 0; \
   offscale

#define IMAGE_RING(x, sz) \
   set { name: x; \
      image { image: x"1.png" COMP; size:  (sz/2)   (sz/2)  99999   99999;   } \
      image { image: x"2.png" COMP; size:  (sz/4)   (sz/4)  (sz/2)  (sz/2);  } \
      image { image: x"3.png" COMP; size:  (sz/8)   (sz/8)  (sz/4)  (sz/4);  } \
      image { image: x"4.png" COMP; size:  (sz/16)  (sz/16) (sz/8)  (sz/8);  } \
      image { image: x"5.png" COMP; size:       0        0  (sz/16) (sz/16); } \
   }
#define BUSY(x, start1, start2, stop1, stop2) \
   program { signal: start1; source: start2; \
      action: STATE_SET "visible" 0.0; \
      transition: SINUSOIDAL 1.0 USE_DURATION_FACTOR 1; \
      target: "busy"; } \
   program { signal: start1; source: start2; \
      action: STATE_SET "default" 0.0; \
      target: "busy1"; \
      target: "busy2"; \
      target: "busy3"; \
      after: "busy-p11"; \
      after: "busy-p21"; \
      after: "busy-p31"; } \
   program { signal: stop1; source: stop2; \
      action: STATE_SET "default" 0.0; \
      transition: SINUSOIDAL 1.0 USE_DURATION_FACTOR 1; \
      target: "busy"; \
      after: "busy_stop2"; } \
   program { name: "busy_stop2"; \
      action: ACTION_STOP; \
      target: "busy-p11"; \
      target: "busy-p12"; \
      target: "busy-p21"; \
      target: "busy-p22"; \
      target: "busy-p31"; \
      target: "busy-p32"; } \
   part { name: "busy"; type: RECT; \
      description { state: "default" 0.0; \
         rel1.to: x; rel2.to: x; \
         color: 255 255 255 0; /* no cc */ visible: 0; } \
      description { state: "visible" 0.0; \
         inherit: "default" 0.0; \
         color: 255 255 255 255; /* no cc */ visible: 1; } } \
   part { name: "busy1"; \
      clip_to: "busy"; \
      description { state: "default" 0.0; \
         rel1.to: "busy"; rel2.to: "busy"; \
         aspect: 1.0 1.0; aspect_preference: BOTH; \
         image.normal: "ringa"; \
         color_class: "/fg/normal/progress/busy/1"; \
         map.on: 1; \
         map.smooth: 1; \
         map.rotation.center: "busy"; \
         map.rotation.z: 0; } \
      description { state: "default" 1.0; \
         inherit: "default" 0.0; \
         map.rotation.z: 360; } } \
   program { name: "busy-p11"; \
      action: STATE_SET "default" 1.0; \
      transition: LINEAR 1.0; \
      target: "busy1"; \
      after: "busy-p12"; } \
   program { name: "busy-p12"; \
      action: STATE_SET "default" 0.0; \
      target: "busy1"; \
      after: "busy-p11"; } \
   part { name: "busy2"; \
      clip_to: "busy"; \
      description { state: "default" 0.0; \
         rel1.to: "busy"; rel2.to: "busy"; \
         aspect: 1.0 1.0; aspect_preference: BOTH; \
         image.normal: "ringb"; \
         color_class: "/fg/normal/progress/busy/2"; \
         map.on: 1; \
         map.smooth: 1; \
         map.rotation.center: "busy"; \
         map.rotation.z: 420; } \
      description { state: "default" 1.0; \
         inherit: "default" 0.0; \
         map.rotation.z: 80; } } \
   program { name: "busy-p21"; \
      action: STATE_SET "default" 1.0; \
      transition: LINEAR 0.7; \
      target: "busy2"; \
      after: "busy-p22"; } \
   program { name: "busy-p22"; \
      action: STATE_SET "default" 0.0; \
      target: "busy2"; \
      after: "busy-p21"; } \
   part { name: "busy3"; \
      clip_to: "busy"; \
      description { state: "default" 0.0; \
         rel1.to: "busy"; rel2.to: "busy"; \
         aspect: 1.0 1.0; aspect_preference: BOTH; \
         image.normal: "ringc"; \
         color_class: "/fg/normal/progress/busy/3"; \
         map.on: 1; \
         map.smooth: 1; \
         map.rotation.center: "busy"; \
         map.rotation.z: 170; } \
      description { state: "default" 1.0; \
         inherit: "default" 0.0; \
         map.rotation.z: 530; } } \
   program { name: "busy-p31"; \
      action: STATE_SET "default" 1.0; \
      transition: LINEAR 1.4; \
      target: "busy3"; \
      after: "busy-p32"; } \
   program { name: "busy-p32"; \
      action: STATE_SET "default" 0.0; \
      target: "busy3"; \
      after: "busy-p31"; }

#define ICON         1
#define LABEL        2
#define MASK         3
#define DISABLE      4
#define PRESSED      8
#define BACKGROUND  16
#define BUTTONMODE_SCRIPT \
      public btmode; \
      public eval_mode(m) { \
         new m1 = m & MASK; \
         new d  = m & DISABLE; \
         new p  = m & PRESSED; \
         new bg = m & BACKGROUND; \
         if (bg) { \
            set_state(PART:"base", "hidden", 0.0); \
            set_state(PART:"elm.swallow.background", "visible", 0.0); \
         } else { \
            set_state(PART:"elm.swallow.background", "default", 0.0); \
            if (!d) { \
               if (!p) { \
                  set_state(PART:"base", "default", 0.0); \
                  set_state(PART:"shadow", "default", 0.0); \
               } else { \
                  set_state(PART:"base", "pressed", 0.0); \
                  set_state(PART:"shadow", "pressed", 0.0); \
               } \
            } else { \
               set_state(PART:"base", "disabled", 0.0); \
               set_state(PART:"shadow", "disabled", 0.0); \
            } \
         } \
         if (m1 == (ICON | LABEL)) { \
            if (!d) { \
               set_state(PART:"elm.swallow.content", "visible", 0.0); \
               set_state(PART:"event", "default", 0.0); \
               if (!p) { \
                  set_state(PART:"elm.text", "visible", 0.0); \
                  set_state(PART:"icon_clip", "default", 0.0); \
               } else { \
                  set_state(PART:"elm.text", "pressed_visible", 0.0); \
                  set_state(PART:"icon_clip", "pressed", 0.0); \
               } \
            } else { \
               set_state(PART:"elm.swallow.content", "visible", 0.0); \
               set_state(PART:"elm.text", "disabled_visible", 0.0); \
               set_state(PART:"icon_clip", "disabled", 0.0); \
               set_state(PART:"event", "disabled", 0.0); \
            } \
         } else if (m1 == (ICON)) { \
            if (!d) { \
               set_state(PART:"elm.swallow.content", "icononly", 0.0); \
               set_state(PART:"event", "default", 0.0); \
               set_state(PART:"elm.text", "default", 0.0); \
               if (!p) \
                  set_state(PART:"icon_clip", "default", 0.0); \
               else \
                  set_state(PART:"icon_clip", "pressed", 0.0); \
            } else { \
               set_state(PART:"elm.swallow.content", "icononly", 0.0); \
               set_state(PART:"elm.text", "default", 0.0); \
               set_state(PART:"icon_clip", "disabled", 0.0); \
               set_state(PART:"event", "disabled", 0.0); \
            } \
         } else if (m1 == (LABEL)) { \
            if (!d) { \
               set_state(PART:"elm.swallow.content", "default", 0.0); \
               set_state(PART:"icon_clip", "default", 0.0); \
               set_state(PART:"event", "default", 0.0); \
               if (!p) \
                  set_state(PART:"elm.text", "textonly", 0.0); \
               else \
                  set_state(PART:"elm.text", "pressed_textonly", 0.0); \
            } else { \
               set_state(PART:"elm.swallow.content", "default", 0.0); \
               set_state(PART:"elm.text", "disabled_textonly", 0.0); \
               set_state(PART:"icon_clip", "disabled", 0.0); \
               set_state(PART:"event", "disabled", 0.0); \
            } \
         } else { \
            if (!d) { \
               set_state(PART:"elm.swallow.content", "default", 0.0); \
               set_state(PART:"icon_clip", "default", 0.0); \
               set_state(PART:"event", "default", 0.0); \
            } else { \
               set_state(PART:"elm.swallow.content", "default", 0.0); \
               set_state(PART:"icon_clip", "disabled", 0.0); \
               set_state(PART:"event", "disabled", 0.0); \
            } \
         } \
      } \
      flag_set(flag) { \
         new m = get_int(btmode) | flag; \
         set_int(btmode, m); eval_mode(m); \
      } \
      flag_unset(flag) { \
         new m = get_int(btmode) & ~flag; \
         set_int(btmode, m); eval_mode(m); \
      }
#define BUTTONMODE_SCRIPT2 \
      public btmode; \
      public eval_mode(m) { \
         new m1 = m & MASK; \
         new d  = m & DISABLE; \
         new p  = m & PRESSED; \
         new bg = m & BACKGROUND; \
         if (bg) { \
            set_state(PART:"base", "hidden", 0.0); \
            set_state(PART:"efl.background", "visible", 0.0); \
         } else { \
            set_state(PART:"efl.background", "default", 0.0); \
            if (!d) { \
               if (!p) { \
                  set_state(PART:"base", "default", 0.0); \
                  set_state(PART:"shadow", "default", 0.0); \
               } else { \
                  set_state(PART:"base", "pressed", 0.0); \
                  set_state(PART:"shadow", "pressed", 0.0); \
               } \
            } else { \
               set_state(PART:"base", "disabled", 0.0); \
               set_state(PART:"shadow", "disabled", 0.0); \
            } \
         } \
         if (m1 == (ICON | LABEL)) { \
            if (!d) { \
               set_state(PART:"efl.content", "visible", 0.0); \
               set_state(PART:"event", "default", 0.0); \
               if (!p) { \
                  set_state(PART:"efl.text", "visible", 0.0); \
                  set_state(PART:"icon_clip", "default", 0.0); \
               } else { \
                  set_state(PART:"efl.text", "pressed_visible", 0.0); \
                  set_state(PART:"icon_clip", "pressed", 0.0); \
               } \
            } else { \
               set_state(PART:"efl.content", "visible", 0.0); \
               set_state(PART:"efl.text", "disabled_visible", 0.0); \
               set_state(PART:"icon_clip", "disabled", 0.0); \
               set_state(PART:"event", "disabled", 0.0); \
            } \
         } else if (m1 == (ICON)) { \
            if (!d) { \
               set_state(PART:"efl.content", "icononly", 0.0); \
               set_state(PART:"event", "default", 0.0); \
               set_state(PART:"efl.text", "default", 0.0); \
               if (!p) \
                  set_state(PART:"icon_clip", "default", 0.0); \
               else \
                  set_state(PART:"icon_clip", "pressed", 0.0); \
            } else { \
               set_state(PART:"efl.content", "icononly", 0.0); \
               set_state(PART:"efl.text", "default", 0.0); \
               set_state(PART:"icon_clip", "disabled", 0.0); \
               set_state(PART:"event", "disabled", 0.0); \
            } \
         } else if (m1 == (LABEL)) { \
            if (!d) { \
               set_state(PART:"efl.content", "default", 0.0); \
               set_state(PART:"icon_clip", "default", 0.0); \
               set_state(PART:"event", "default", 0.0); \
               if (!p) \
                  set_state(PART:"efl.text", "textonly", 0.0); \
               else \
                  set_state(PART:"efl.text", "pressed_textonly", 0.0); \
            } else { \
               set_state(PART:"efl.content", "default", 0.0); \
               set_state(PART:"efl.text", "disabled_textonly", 0.0); \
               set_state(PART:"icon_clip", "disabled", 0.0); \
               set_state(PART:"event", "disabled", 0.0); \
            } \
         } else { \
            if (!d) { \
               set_state(PART:"efl.content", "default", 0.0); \
               set_state(PART:"icon_clip", "default", 0.0); \
               set_state(PART:"event", "default", 0.0); \
            } else { \
               set_state(PART:"efl.content", "default", 0.0); \
               set_state(PART:"icon_clip", "disabled", 0.0); \
               set_state(PART:"event", "disabled", 0.0); \
            } \
         } \
      } \
      flag_set(flag) { \
         new m = get_int(btmode) | flag; \
         set_int(btmode, m); eval_mode(m); \
      } \
      flag_unset(flag) { \
         new m = get_int(btmode) & ~flag; \
         set_int(btmode, m); eval_mode(m); \
      }
